
import re

from utils.os import read_url_yaml, read_extractall_yaml

"""
:param dict: 已经获取了extract文件的值的字典
:return 字典
把测试用例中的内容写到dict字典中
"""
def parms_extractall(dict):
    value = read_extractall_yaml()
    for key in dict:
        for key2 in value:
            if key == key2:
                dict[key] = value[key]
    return dict
"""
:param list: url参数名列表
:param yaml_case: 测试用例中的值
:return 字典
直接生成一个字典，然后把测试用例中的值写入到字典中
"""
def parmas_case(list,yaml_case):
    dict = {}
    for key in list:
        try:
            dict[key] = yaml_case['request']['params'][key]
        except (KeyError):
            dict[key] = ""
            continue
    return dict

"""
:param url_name: 接口名称
:return 通过url截取的list列表
通过接口名称获取extract.yaml文件的
"""
def params_list(url_name):
    value = read_url_yaml()
    url = value[url_name]
    rel_first = r'\?(.*?)='
    re_last = r'&(.*?)='
    parm_first = re.findall(rel_first,url)
    parm_last = re.findall(re_last, url)
    parm = []
    parm.extend(parm_first)
    parm.extend(parm_last)
    return parm